﻿@model Bricks.Site.Models.ContractExpenseView
@{
    ViewBag.Title = "ExpenseList";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}
<script type="text/javascript">
    $(function () {
        //当页面首次刷新的时候执行的事件
        initTable();
    });

    function initTable() {
        var contractID = $("#hContractID").val();
        var contractName = $("#hContractName").val();
        var contractMoney = $("#hContractMoney").val();
        var constructionDrawMoney = $("#hConstructionDrawMoney").val();
        var alterIncreaseOrDecreaseMoney = $("#hAlterIncreaseOrDecreaseMoney").val();
        var afterAlterMoney = $("#hAfterAlterMoney").val();
        var approvalMoney = $("#hApprovalMoney").val();
        var paymentPercentage = $("#hPaymentPercentage").val();
        $('#myDataGrid').datagrid({
            url: '/Expense/GetExpenseList?contractID=' + contractID,//一个用以从远程站点请求数据的超链接地址
            iconCls: 'icon-bricks',
            nowrap: true,//当数据长度超出列宽时将会自动截取
            autoRowHeight: false,
            striped: true,//设置为true将交替显示行背景
            collapsible: true,
            pagination: true,
            pageSize: 20,
            rownumbers: true,
            remoteSort: false,
            idField: 'ID',//表明该列是一个唯一列。
            singleSelect: true,
            fitColumns: true,
            sortName: "ContractStages",
            sortOrder:"desc",
            columns: [
                [
                        { title: '合同名称', width: 100 },
                        { title: contractName, width: 150 },
                        { title: '合同总额', width: 100 },
                        { title: contractMoney, width: 100 },
                        { title: '施工图金额', width: 100 },
                        { title: constructionDrawMoney, width: 100 },
                        { title: '', width: 350 },
                ],
                [
                        { title: '变更增减金额', width: 100 },
                        { title: alterIncreaseOrDecreaseMoney, width: 150 },
                        { title: '变更后金额', width: 100 },
                        { title: afterAlterMoney, width: 100 },
                        { title: '已审批付款比例', width: 100 },
                        { title: paymentPercentage, width: 100 },
                        { title: '', width: 350 },
                ],
                [
                        { title: '付款期次', field: 'ContractStagesStr', rowspan: 2, width: 100, sortable: true },
                        { title: '申请', width: 350, colspan: 3 },
                        { title: '审批', width: 300, colspan: 2 },
                        { title: '', width: 350 },
                ],
                [
                        { title: 'ExpenseID', field: 'ExpenseID', hidden: true },
                        { title: 'HandleState', field: 'HandleState', hidden: true },
                        { title: 'ContractStages', field: 'ContractStages', hidden: true },
                        { title: '申请人', field: 'RequestPersonName', width: 150, sortable: true },
                        { title: '申请金额', field: 'RequestMoneyForRequestPerson', width: 100, sortable: true },
                        { title: '申请时间', field: 'RequestDate', width: 100, sortable: true, formatter: function (value, rec) { if (value) { return dateConvert(value); } } },
                        { title: '审批金额', field: 'ApprovalMoney', width: 100, sortable: true },
                        { title: '审批时间', field: 'LastUpdateTime', width: 100, sortable: true, formatter: function (value, rec) { if (value) { return dateConvert(value); } } },
                        { title: '流程监控', field: 'ProcedureMonitor', rowspan: 2, width: 350, sortable: true },
                ]],
            toolbar: '#myToolBar',
            onDblClickRow: function (rowIndex, rowData) {
                PopExpense(rowData.HandleState, rowData.ExpenseID);
            }
        });
    }

    function PopExpense(handleState, id) {
        var processType = '1';
        if (handleState == "0") {
            processType = '2';
        }
        showMyWindow("#myWindow", "", "/Expense/Expense?MenuCode=Expense&sourceType=0&processType=" + processType + "&sourceID=&expenseID=" + id, 1000, 500, true, true, true);
    }

    function PopAddExpense(department) {
        var projectID = $("#hProjectID").val();
        var contractID = $("#hContractID").val();
        var contractSource = $("#hContractSource").val();
        showMyWindow("#myWindow", "", "/Expense/Expense?MenuCode=Expense&sourceType=1&processType=&sourceID=&lastUpdateUserDepartment=" + department + "&projectID=" + projectID + "&contractID=" + contractID + "&contractSource=" + contractSource, 1000, 500, true, true, true);
    }

    var ExpenseList =
    {
        AddExpense: function () {
            $.post("/UserMenuAction/GetUserDepartmentForFlow?menuCode=ExpenseList", function (userDepartment) {
                if (userDepartment == "") {
                    showMyWindow("#myWindow", "选择机构", "/UserMenuAction/ShowOrgByUserForFlow?menuCode=ExpenseList", 500, 280, true, false);
                }
                else if (userDepartment == "**********") {
                    $.messager.alert('操作提示', '当前用户不属于任何机构，请先设置所属机构！', 'info');
                }
                else if (userDepartment == "++++++++++") {
                    $.messager.alert('操作提示', '当前用户的机构不属于流程申请配置机构，不能新增！', 'info');
                }
                else {
                    PopAddExpense(userDepartment);
                }
            });
            //$.post("/UserMenuAction/GetUserDepartment?menuCode=ExpenseList&actionCode=AddExpense", function (userDepartment) {
            //    if (userDepartment == "") {
            //        showMyWindow("#myWindow", "选择机构", "/UserMenuAction/ShowOrgByUser?menuCode=ExpenseList&actionCode=AddExpense", 500, 280, true, false);
            //    }
            //    else if (userDepartment == "**********") {
            //        $.messager.alert('操作提示', '当前用户不属于任何机构，请先设置所属机构！', 'info');
            //    }
            //    else {
            //        PopAddExpense(userDepartment);
            //    }
            //});
        },

        DeleteExpense: function () {
            var selectExpense = $('#myDataGrid').datagrid('getSelections');
            if (selectExpense == "[]") {
                $.messager.alert('操作提示', '请选择要删除的行！', 'info');
            }
            else {
                $.messager.confirm('操作提示', "确认删除第[ " + selectExpense[0].ExpenseNum + " ]个付款次数吗？", function (r) {
                    if (r) {
                        $.post("/Expense/DeleteSelectExpense?expenseID=" + selectExpense[0].ExpenseID, function (res) {
                            if (res == "Success") {
                                //移除删除的数据
                                $("#myDataGrid").datagrid("reload");
                                $("#myDataGrid").datagrid("clearSelections");
                                $.messager.alert('操作提示', '删除成功!', 'info');
                            }
                            else {
                                if (res == "") {
                                    $.messager.alert('操作提示', '删除失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');
                                }
                                else {
                                    $.messager.alert('操作提示', res, 'info');
                                }
                            }
                        });
                    }
                });
            }
        },

        ReverseAudit: function () {
            var selectExpense = $('#myDataGrid').datagrid('getSelections');
            if (selectExpense.length==0) {
                $.messager.alert('操作提示', '请选择要反审核的行！', 'info');
            }
            else {
                if (selectExpense[0].HandleState == "2") {
                    $.post("/Flow/ExpenseReverseAudit?expenseID=" + selectExpense[0].ExpenseID, function (res) {
                        if (res == "Success") {
                            //移除删除的数据
                            $("#myDataGrid").datagrid("reload");
                            $("#myDataGrid").datagrid("clearSelections");
                            $.messager.alert('操作提示', '反审核成功!', 'info');
                        }
                        else {
                            if (res == "") {
                                $.messager.alert('操作提示', '反审核失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');
                            }
                            else {
                                $.messager.alert('操作提示', res, 'info');
                            }
                        }
                    });
                }
                else {
                    $.messager.alert('操作提示', '反审核的记录必须是已经审核完成的！', 'info');
                }
            }
        }
    }

    function CloseSelf() {
        window.parent.cancelPopWindow();
    }

    function cancelPopWindow(handleState) {
        if (handleState == "0") {
            initTable();
        }
        colseMyWindow("#myWindow");
    }

    function CloseWindow(data) {
        colseMyWindow("#myWindow");
        initTable();
        $.EasyuiSlide(data);
    }
</script>
<input type="hidden" id="hProjectID" name="ProjectID" value="@Model.ProjectID" />
<input type="hidden" id="hContractID" name="ContractID" value="@Model.ContractID" />
<input type="hidden" id="hContractName" name="ContractName" value="@Model.ContractName" />
<input type="hidden" id="hContractSource" name="ContractSource" value="@Model.ContractSource" />
<input type="hidden" id="hContractMoney" name="ContractMoney" value="@Model.ContractMoney" />
<input type="hidden" id="hConstructionDrawMoney" name="ConstructionDrawMoney" value="@Model.ConstructionDrawMoney" />
<input type="hidden" id="hAlterIncreaseOrDecreaseMoney" name="AlterIncreaseOrDecreaseMoney" value="@Model.AlterIncreaseOrDecreaseMoney" />
<input type="hidden" id="hAfterAlterMoney" name="AfterAlterMoney" value="@Model.AfterAlterMoney" />
<input type="hidden" id="hApprovalMoney" name="ApprovalMoney" value="@Model.ApprovalMoney" />
<input type="hidden" id="hPaymentPercentage" name="PaymentPercentage" value="@Model.PaymentPercentage" />
<table id="myDataGrid" fit="true"></table>
<div id="myToolBar">
    @Html.Raw(ViewBag.ToolBarInfo)
    <a href="#" id="btnCancel" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-ok'" onclick="CloseSelf();">关闭</a>
</div>
